#install.packages("devtools")
#devtools::install_github("thomasp85/transformr")
library(gganimate)

result_1 <- st_read("./Red_Bird.shp") %>% filter(!facet %in% 
                    c(3:55, 56:60, 81)) %>% st_union() %>% st_sfc() %>% st_sf() %>% 
  mutate(facet = 1)
## Reading layer `Red_Bird' from data source 
##   `C:\Users\jacek\JacekPardyak.github.io\inkscaper\Red_Bird.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 93 features and 1 field
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: 238.9009 ymin: -837.4039 xmax: 1105.521 ymax: 40.07607
## CRS:           NA
result_2 <- st_read("./Red_Bird.shp") %>% filter(facet %in% 
                    c(3:55, 56:60, 81)) %>% st_union() %>% st_sfc() %>% st_sf() %>% 
  mutate(facet = 2)
## Reading layer `Red_Bird' from data source 
##   `C:\Users\jacek\JacekPardyak.github.io\inkscaper\Red_Bird.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 93 features and 1 field
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: 238.9009 ymin: -837.4039 xmax: 1105.521 ymax: 40.07607
## CRS:           NA
result <- result_1 %>% bind_rows(result_2)
result %>% ggplot() +
  geom_sf()  + 
  transition_states(
    facet,
    transition_length = 2,
    state_length = 1
  ) +
  enter_fade() + 
  exit_shrink() +
  ease_aes('sine-in-out')

anim_save("./Red_Bird.gif")